#include <iostream>
#include <unistd.h>
#include <signal.h>

using namespace std;

void PrintPending(sigset_t &pending)
{
    for (int signo = 31; signo >= 1; signo--)
    {
        if (sigismember(&pending, signo))
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout << "\n\n";
}

int main()
{
    sigset_t bset, oset, pending;
    sigemptyset(&bset);
    sigemptyset(&oset);
    sigaddset(&bset, 2);
    sigaddset(&bset, 40);

    sigprocmask(SIG_SETMASK, &bset, &oset);

    while(true)
    {
        cout << "pid: " << getpid() << endl;
        int n = sigpending(&pending);
        if(n < 0) continue;
        PrintPending(pending);
        sleep(1);
    }
    // 发送信号

    return 0;
}